﻿using MoreMountains.NiceVibrations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class Key : MonoBehaviour, IPointerDownHandler
{
    AudioClip clip;

    void PlaySound()
    {
        AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
    }
    void Vibrate()
    {
        GameFunction.Vibrate(GameData.keyVibrateIndex);
    }
    void GenerateMusicNote()
    {
        GameObject musicNote = Manage.instance.musicalNote_prefab;
        //仅适用于当前Canvas布局
        Vector3 pos = this.transform.position;
        pos.z = 0;
        GameObject.Instantiate(musicNote, pos, Quaternion.identity);
    }

    public void SetClip(AudioClip clip)
    {
        this.clip = clip;
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        PlaySound();
        GenerateMusicNote();
        Vibrate();
    }
}
